package com.kgc.activiticonsumer.controller;

import com.kgc.activiti.pojo.WorkFlow;
import com.kgc.activiti.util.ResponseMsg;
import com.kgc.activiticonsumer.feign.WorkFlowFeign;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RequestMapping("workFlow")
@RestController
@CrossOrigin
public class WorkFlowController {

    private Logger logger = LoggerFactory.getLogger(getClass());
    @Autowired
    private WorkFlowFeign workFlowFeign;

    @RequestMapping("exportWorkFlow")
    public ResponseMsg exportWorkFlow(WorkFlow workFlow, String xml){
        ResponseMsg msg = workFlowFeign.exportWorkFlow(workFlow, xml);
        return msg;
    }

    @RequestMapping("getWorkFlowList")
    public ResponseMsg getWorkFlowList(@RequestBody Map<String, Object> paramMap) {
        logger.info("WorkFlowController getWorkFlowList paramMap:"+paramMap);
        ResponseMsg msg = workFlowFeign.getWorkFlowList(paramMap);
        logger.debug("WorkFlowController getWorkFlowList msg:"+msg);
        return msg;
    }

    @RequestMapping("showWorkFlow")
    public ResponseMsg showWorkFlow(String url) {
        logger.info("WorkFlowController showWorkFlow url:"+url);
        ResponseMsg msg = workFlowFeign.showWorkFlow(url);
        logger.debug("WorkFlowController showWorkFlow msg:"+msg);
        return msg;
    }

    @RequestMapping("editWorkFlow")
    public ResponseMsg editWorkFlow(WorkFlow workFlow, String xml){
        logger.info("WorkFlowController EditWorkFlow workFlow:"+workFlow+"xml:"+xml);
        ResponseMsg msg = workFlowFeign.editWorkFlow(workFlow, xml);
        logger.debug("WorkFlowController EditWorkFlow msg:"+msg);
        return msg;
    }

    @RequestMapping("checkCodeExit")
    public ResponseMsg checkCodeExit(String code) {
        logger.info("WorkFlowController checkCodeExit code:"+code);
        ResponseMsg msg = workFlowFeign.checkCodeExit(code);
        logger.debug("WorkFlowController checkCodeExit msg:"+msg);
        return msg;
    }

    @RequestMapping("checkNameExit")
    public ResponseMsg checkNameExit(String name) {
        logger.info("WorkFlowController checkNameExit name:"+name);
        ResponseMsg msg = workFlowFeign.checkNameExit(name);
        logger.debug("WorkFlowController checkNameExit msg:"+msg);
        return msg;
    }

    @RequestMapping("checkTypeExit")
    public ResponseMsg checkTypeExit(Integer type) {
        logger.info("WorkFlowController checkTypeExit type:"+type);
        ResponseMsg msg = workFlowFeign.checkTypeExit(type);
        logger.debug("WorkFlowController checkTypeExit msg:"+msg);
        return msg;
    }

    @RequestMapping("deployWorkFlow")
    public ResponseMsg deployWorkFlow(String url) {
        logger.info("WorkFlowController deployWorkFlow url:"+url);
        ResponseMsg msg = workFlowFeign.deployWorkFlow(url);
        logger.debug("WorkFlowController deployWorkFlow msg:"+msg);
        return msg;
    }

    @RequestMapping("reSubmit")
    public ResponseMsg reSubmit(@RequestBody Map<String, Object> paramMap) {
        logger.info("WorkFlowController reSubmit paramMap:"+paramMap);
        ResponseMsg msg = workFlowFeign.reSubmit(paramMap);
        logger.debug("WorkFlowController reSubmit msg:"+msg);
        return msg;
    }

    @RequestMapping("startProcess")
    public ResponseMsg startProcess(@RequestBody Map<String, Object> paramMap) {
        logger.info("WorkFlowController startProcess paramMap:"+paramMap);
        ResponseMsg msg = workFlowFeign.startProcess(paramMap);
        logger.debug("WorkFlowController startProcess msg:"+msg);
        return msg;
    }
}
